@extends("admin.base")

@section("page")
    <div class="container-fluid p-4">
        <h3>电影信息添加页面</h3>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body col-12">
                        <form id="typesform" action="/movieaddInfo" method="post" enctype="multipart/form-data">
                            {{--                        <form id="typesform">--}}
                            @csrf
                            <input type="hidden" name="id" value="{{isset($movie)?$movie->id:0}}">
                            <div class="row">
                                <div class="col-3">
                                    <div class="p-1">
                                        <label class="form-label" for="formrow-firstname-input">中文名称</label>
                                        <input type="text" name="name_ch" class="form-control" value="{{isset($movie)?$movie->name_ch:""}}"
                                               id="formrow-firstname-input">
                                    </div>
                                    <div class="p-1 pt-4">
                                        <div class="mb-3">
                                            <label class="form-label" for="formrow-email-input">维吾尔文名称</label>
                                            <input type="text" name="name_uy" class="form-control" value="{{isset($movie)?$movie->name_uy:""}}"
                                                   id="formrow-email-input">
                                        </div>
                                    </div>
                                    <div class="p-1">
                                        <div class="mb-3">
                                            <label class="form-label" for="formrow-password-input">简介</label>
                                            <textarea name="description" class="form-control" rows="5"> {{isset($movie)?$movie->description:""}} </textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="offset-1 col-3">
                                    <div class="p-1">
                                        <div class="mb-3">
                                            <label class="form-label" for="formrow-password-input">类型</label>
                                            <div>
                                                <select name="type" class="form-control">
                                                    @foreach($types as $type)
                                                        <option {{isset($movie)?($movie->type==$type->id?"selected":""):""}} value="{{$type->id}}">{{$type->name_ch}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="p-1">
                                        <label class="form-label" for="formrow-firstname-input">国籍</label>
                                        <div>
                                            <select name="country" class="form-control">
                                                @foreach($countries as $country)
                                                    <option {{isset($movie)?($movie->country==$country->id?"selected":""):""}} value="{{$country->id}}">{{$country->name_ch}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="p-1 pt-4">
                                        <label class="form-label" for="formrow-firstname-input">年份</label>
                                        <div>
                                            <select name="year" class="form-control">
                                                <option {{isset($movie)?($movie->year==1?"selected":""):""}} value="1">1980</option>
                                                <option {{isset($movie)?($movie->year==2?"selected":""):""}} value="2">1990</option>
                                                <option {{isset($movie)?($movie->year==3?"selected":""):""}} value="3">2000</option>
                                                <option {{isset($movie)?($movie->year==4?"selected":""):""}} value="4">2010</option>
                                                <option {{isset($movie)?($movie->year==5?"selected":""):""}} value="5">2020</option>
                                                <option {{isset($movie)?($movie->year==6?"selected":""):""}} value="6">2021</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="p-1 pt-3">
                                        <label class="form-label" for="formrow-firstname-input">语言</label>
                                        <div>
                                            <select name="lang" class="form-control">
                                                <option {{isset($movie)?($movie->lang==1?"selected":""):""}} value="1">英语</option>
                                                <option {{isset($movie)?($movie->lang==2?"selected":""):""}} value="2">国语</option>
                                                <option {{isset($movie)?($movie->lang==3?"selected":""):""}} value="3">维吾尔语</option>
                                                <option {{isset($movie)?($movie->lang==4?"selected":""):""}} value="4">哈萨克语</option>
                                                <option {{isset($movie)?($movie->lang==5?"selected":""):""}} value="5">柯尔克孜语</option>
                                                <option {{isset($movie)?($movie->lang==6?"selected":""):""}} value="6">乌兹别克语</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="offset-1 col-3">
                                    <div class="p-1">
                                        <label class="form-label" for="formrow-firstname-input">得分</label>
                                        <input type="text" name="score" class="form-control" value="{{isset($movie)?$movie->score:""}}"
                                               id="formrow-firstname-input">
                                    </div>
                                    <div class="p-1">
                                        <label class="form-label" for="formrow-firstname-input">图片</label>
                                        <input type="file" class="filestyle" name="img" data-buttonname="btn-secondary">
                                        @if(isset($movie))
                                            <img src="{{$movie->img}}" width="40px" height="40px" alt="">
                                            @endif
                                    </div>
                                    <div class="p-1 pt-4">
                                        <div class="mb-3">
                                            <label class="form-label" for="formrow-email-input">视频</label>
                                            <input type="file" class="filestyle" name="movie"
                                                   data-buttonname="btn-secondary">
                                            @if(isset($movie))
                                                <video src="{{$movie->movie}}" controls width="100px" height="60px"></video>
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="mt-3 mb-3 p-1">
                                <button type="submit" class="btn btn-primary w-md"> 提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section("scripts")
    <script>
        $(function (){
            let result = '{{session("result")?session("result"):""}}';
            if(result=="OK"){
                swal({
                    title: "操作成功",
                    text: "电影数据填写成功",
                    icon: "success",
                    button: "知道了",
                }).then((willDelete) => {
                    if (willDelete) {
                        location.href = "/kino";
                    }
                });
            }

            if(result=="NO"){
                swal({
                    title: "操作失败",
                    text: "电影数据填写惨败",
                    icon: "error",
                    button: "知道了",
                });
            }
        });
    </script>
@endsection
